import sys
from PyQt5.QtWidgets import QApplication, QTableWidget, QTableWidgetItem
from openpyxl import Workbook

app = QApplication(sys.argv)

# 创建一个QTableWidget实例
table = QTableWidget()
table.setRowCount(5)
table.setColumnCount(3)

# 添加一些数据
for i in range(5):
    for j in range(3):
        table.setItem(i, j, QTableWidgetItem(f"Cell ({i+1}, {j+1})"))

# 将QTableWidget的内容导出到Excel文件
workbook = Workbook()
worksheet = workbook.active

for i in range(table.rowCount()):
    for j in range(table.columnCount()):
        worksheet.cell(row=i+1, column=j+1, value=table.item(i, j).text())

workbook.save("output.xlsx")

# sys.exit(app.exec_())
